import { Button, Modal, message, Spin } from 'antd';

const confirm = Modal.confirm;
import { WeaErrorPage, WeaTools, WeaAlertPage, WeaAuth, WeaTable } from 'ecCom';
import { WeaTableNew, WeaSwitch } from 'comsMobx';
import { inject, observer } from 'mobx-react';
import { toJS } from 'mobx';
import { WeaLocaleProvider } from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;
const columns = [
  {
    title: getLabel(21956, '对象类型'),
    dataIndex: 'shareType',
  },
  {
    title: getLabel(106, '对象'),
    dataIndex: 'relatedshareid',
  },
  {
    title: getLabel(683, '安全级别'),
    dataIndex: 'seclevel',
  },
  {
    title: getLabel(385, '权限'),
    dataIndex: 'sharelevel',
  },
];

@inject('sellChanceCarsAuthStore')
@observer
class SellChanceCarsAuth extends React.Component {
  constructor(props) {
    super(props);
  }

  // render before
  componentWillMount() {
    this.props.sellChanceCarsAuthStore.componentWillMount(this);
  }

  // render after
  componentDidMount() {
    this.props.sellChanceCarsAuthStore.componentDidMount();
  }

  // component remove before
  componentWillUnmount() {
    this.props.sellChanceCarsAuthStore.componentWillUnmount();
  }

  render() {
    const { openAuth, openAuthForm, shareCondition, getSelectIds, dataSource } = this.props.sellChanceCarsAuthStore;
    // console.log(shareCondition)
    const rowSelection = {
      onChange: (selectedRowKeys, selectedRows) => {
        this.setState({ selectedRowKeys });
        getSelectIds(selectedRowKeys);
        this.setState({ selectedRows });
      },
      getCheckboxProps: record => ({
        disabled: record.candeleted != '1',
      }),
    };

    const pagination = {
      total: dataSource.length,
      showSizeChanger: true,
      showQuickJumper: true,
      pageSizeOptions: ['10', '20', '50', '100'],
      // showTotal:{total => `Total ${total} items`}
    };
    return (
      <div>
        <WeaTable
          ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@66ufgj`}
          columns={columns}
          dataSource={dataSource}
          rowSelection={rowSelection}
          pagination={pagination}
        />
        <WeaAuth
          ecId={`${this && this.props && this.props.ecId || ''}_WeaAuth@85ii8c`}
          ref="auth"
          style={{ width: 800, height: 500 }}
          visible={openAuth}
          conditions={toJS(shareCondition)}
          title={getLabel(18645, '添加共享')}
          icon={'icon-coms-crm'}
          iconBgcolor="#96358a"
          onOk={(data) => { this.onOkClick(data); openAuthForm(false); }}
          onCancel={() => {
            openAuthForm(false);
          }}
        />
      </div>
    );
  }

    onOkClick = (value) => {
      this.props.sellChanceCarsAuthStore.saveShareForm({ ...value });
    }
}

export default WeaTools.tryCatch(React,
  props => <WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@w2a2d0`} msg={props.error ? props.error : getLabel(129417, '服务器运行出错，请联系系统管理员！')} />,
  { error: '' },
)(SellChanceCarsAuth);
